package com.will.txj.aj.security.config.auth;

import com.will.txj.common.result.R;
import com.will.txj.common.result.RC;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * @author: wen-yi;
 * @date: 2021/12/5 22:18;
 * @Description: 当账户被踢下线时 如何处理
 */
@Component("myExpiredSessionStrategy")
public class MyExpiredSessionStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        JSONAuthenticationUtil.WriteJSON(event.getRequest(), event.getResponse(), R.fail(RC.USER_ACCOUNT_USE_BY_OTHERS));
    }
}
